﻿using System;
using System.Collections;
using System.Data;
using System.Text;

namespace Coffee.Lists
{
    public class Lst_PriceList : iControls.BaseForm.clBaseList
    {
        public override System.Data.DataTable GetAll()
        {
            return DBLayer.ExecDataTable("sp_Lst_PriceList", "Command", "GetAll");
        }

        public override void Update(ref System.Data.DataTable Data)
        {
            try
            {
                DBLayer.BeginTransaction();

                foreach (DataRow row in Data.Rows)
                {
                    if (row.RowState == DataRowState.Added || row.RowState == DataRowState.Modified)
                    {
                        DBLayer.ExecNonQuery("sp_Lst_PriceList", "Command,ProductID,Price,Notes", "Update",
                            TSoft.Cvert.ToInt32(row["ProductID"], 0), TSoft.Cvert.ToString(row["Name"], ""),
                            TSoft.Cvert.ToString(row["Notes"], ""));
                    }
                }

                DBLayer.CommitTransaction();
            }
            catch
            {
                DBLayer.RollbackTransaction();
            }
        }

        public override void DeleteRow(DataRow Row)
        {
            DBLayer.ExecNonQuery("sp_Lst_PriceList", "Command,ProductID", "DeleteRow", TSoft.Cvert.ToInt32(Row["ProductID"], 0));
        }
    }
}
